<?php
header ( 'Content-Type:text/html; charset=UTF-8' );
@$tid = $_REQUEST ['tid'];
$pdo = new PDO ( 'mysql:dbname=crm; charset=utf8', 'root' );
$s = $pdo->prepare ( 'select * from username where id=:aa' );
$s->execute ( array (
		'aa' => $tid
) );
$data = $s->fetch ( PDO::FETCH_NAMED );
@$name=$data['name'];
@$password=$data['password'];
@$sf=$data['sf'];
@$xm=$data['xm'];
@$tel=$data['tel'];
@$dizhi=$data['dizhi'];

$s = $pdo->prepare ( 'select * from zdkh' );
$s->execute ();
$data1 = $s->fetchAll ( PDO::FETCH_NAMED );
foreach ($data1 as $value){
	if ($name == $value['name']) {
		die(json_encode ( array (
				'fhwb' => '已挑出成功！'
		) ));
	}
}
if($name != @$value ['name']){
	$s = $pdo->prepare ( 'insert into zdkh(name,password,sf,xm,tel,dizhi) values(:name,:password,:sf,:xm,:tel,:dizhi)' );
	$isok=$s->execute (array(
			'name'=>$name,
			'password'=>$password,
			'sf'=>$sf,
			'xm'=>$xm,
			'tel'=>$tel,
			'dizhi'=>$dizhi
	));
	if($isok){
		echo json_encode ( array (
				'fhwb' => '挑出成功！'
		) );
	}else{
		echo json_encode ( array (
				'fhwb' => '挑出失败！'
		) );
	}
}